##########################
#************************#
"""author : qizhang NJU"""
#************************#
##########################
import numpy as np
from matplotlib import pyplot as plt
def read_Himawari(file_name,resolution):
    if resolution==1:
        res=12100000
        nlin=1100
        ncol=11000
    elif resolution==2:
        res=3025000
        nlin=550
        ncol=5500
    else:
        res=48400000
        nlin=2200
        ncol=22000
    formation=[('bn','i1',1),\
            ('bl','i2',1),\
            ('thb','i2',1),\
            ('bo','i1',1),\
            ('sn','S1',16),\
            ('pcn','S1',16),\
            ('oa','S1',4),\
            ('obf','S1',2),\
            ('ot','i2',1),\
            ('ost','float64',1),\
            ('oet','float64',1),\
            ('fct','float64',1),\
            ('thl','i4',1),\
            ('tdl','i4',1),\
            ('qf1','i1',1),\
            ('qf2','i1',1),\
            ('qf3','i1',1),\
            ('qf4','i1',1),\
            ('ffv','S1',32),\
            ('fn','S1',128),\
            ('null1','S1',40),\
            ('bn2','i1',1),\
            ('bl2','i2',1),\
            ('nbpp','i2',1),\
            ('noc','i2',1),\
            ('nol','i2',1),\
            ('cffdb','i1',1),\
            ('null2','S1',40),\
            ('bn3','i1',1),\
            ('bl3','i2',1),\
            ('sl','float64',1),\
            ('CFAC','i4',1),\
            ('LFAC','i4',1),\
            ('COFF','float32',1),\
            ('LOFF','float32',1),\
            ('dfectvs','float64',1),\
            ('eer','float64',1),\
            ('epr','float64',1),\
            ('var1','float64',1),\
            ('var2','float64',1),\
            ('var3','float64',1),\
            ('cfsd','float64',1),\
            ('rt','i2',1),\
            ('rs','i2',1),\
            ('null3','S1',40),\
            ('bn4','i1',1),\
            ('bl4','i2',1),\
            ('ni','float64',1),\
            ('ssplon','float64',1),\
            ('ssplat','float64',1),\
            ('dfects4','float64',1),\
            ('nlat','float64',1),\
            ('nlon','float64',1),\
            ('sp','float64',3),\
            ('mp','float64',3),\
            ('null4','S1',40),\
            ('bn5','i1',1),\
            ('bl5','i2',1),\
            ('bdn','i2',1),\
            ('cwl','float64',1),\
            ('vnobpp','i2',1),\
            ('cvoep','uint16',1),\
            ('cvoposa','uint16',1),\
            ('gfcce','float64',1),\
            ('cfcce','float64',1),\
            ('c0','float64',1),\
            ('c1','float64',1),\
            ('c2','float64',1),\
            ('C0','float64',1),\
            ('C1','float64',1),\
            ('C2','float64',1),\
            ('sol','float64',1),\
            ('pc','float64',1),\
            ('bc','float64',1),\
            ('null5','S1',40),\
            ('b06n01','i1',1),\
            ('b06n02','i2',1),\
            ('b06n03','float64',1),\
            ('b06n04','float64',1),\
            ('b06n05','float64',1),\
            ('b06n06','float64',1),\
            ('b06n07','float64',1),\
            ('b06n08','float64',1),\
            ('b06n09','float64',1),\
            ('b06n10','float64',1),\
            ('b06n11','float32',1),\
            ('b06n12','float32',1),\
            ('b06n13','S1',128),\
            ('b06n14','S1',56),\
            ('b07n01','i1',1),\
            ('b07n02','i2',1),\
            ('b07n03','i1',1),\
            ('b07n04','i1',1),\
            ('b07n05','i2',1),\
            ('b07n06','S1',40),\
            ('b08n01','i1',1),\
            ('b08n02','i2',1),\
            ('b08n03','float32',1),\
            ('b08n04','float32',1),\
            ('b08n05','float64',1),\
            ('b08n06','i2',1),\
            ('b08n07','i2',1),\
            ('b08n08','float32',1),\
            ('b08n09','float32',1),\
            ('b08n10','S1',50),\
            ('b09n01','i1',1),\
            ('b09n02','i2',1),\
            ('b09n03','i2',1),\
            ('b09n04','i2',1),\
            ('b09n05','float64',1),\
            ('b09n06','S1',70),\
            ('b10n01','i1',1),\
            ('b10n02','i4',1),\
            ('b10n03','i2',1),\
            ('b10n04','i2',1),\
            ('b10n05','i2',1),\
            ('b10n06','S1',36),\
            ('b11n01','i1',1),\
            ('b11n02','i2',1),\
            ('b11n03','S1',256),\
            ('b12n01','i2',res)]
    data=np.fromfile('HS_H08_20150731_0000_B01_FLDK_R10_S0'+cell+'10.DAT',dtype=formation)['b12n01'].reshape(nlin,ncol)
    return list(data)

"""test!!!test"""
data=[]
for cell in ['2','3','4','5','6','7']:
    data+=read_Himawari('HS_H08_20150731_0000_B03_FLDK_R05_S0'+cell+'10.DAT',0.5)
plt.imshow(data)
plt.colorbar()
plt.show()
